package com.tarena.lbs.user.controller;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageParam;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.common.principle.UserPrinciple;
import com.tarena.lbs.common.utils.AuthenticationContextUtils;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.po.UserGroupPO;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.ZoneId;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户人群业务相关
 */
@Tag(name = "用户人群管理")
@RestController
@Slf4j
public class UserGroupController {
    @Autowired
    private UserGroupService userGroupService;


    @Operation(summary = "人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")
    public Result<PageResult<UserGroupVO>> pageList(@RequestBody PageParam  param) throws BusinessException{
        log.debug("查询人群数据列表",param.getPageNum(),param.getPageSize());

        PageResult<UserGroupVO> pageResult =userGroupService.selectPageList(param.getPageNum(), param.getPageSize());
        return new Result<PageResult<UserGroupVO>>("0", "success",pageResult);
    }

    @Operation(summary = "保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> save(@RequestBody UserGroupParam param)throws BusinessException
    {
        log.debug("保存人群数据:UserGroupParam:" + param);
        userGroupService.saveUserGroup(param);
        return Result.success();
    }
    @Operation(summary = "更新人群数据")
    @GetMapping("/admin/basic/userGroup/detail/{id}")
    public Result<UserGroupVO> select(@PathVariable("id") Integer id)throws BusinessException
    {
        log.debug("查询人群数据:UserGroupParam:" );
        UserGroupVO vo = userGroupService.selectUserGroupById(id);
        return new Result<>(vo);
    }
}
